package com.gdk.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.gdk.service.ArticleService;
import com.gdk.service.BannerService;
import com.gdk.service.CameraService;
import com.gdk.service.LoginService;
import com.gdk.service.NavigationService;
import com.gdk.service.TreeService;
import com.gdk.utils.XVDateUtils;


/**
 * 摄像头controller
 * */

@Controller
public class CameraController {
	
	@Autowired
    private CameraService cameraService;
	@Autowired
    private TreeService treeService;

	/**
	 * 新增摄像头前查询出所有树
	 * */
	@RequestMapping("/preAddCamera.do")
	public String preAddCamera(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		List<Map<String, Object>> allTree = treeService.selectAllTree();
		request.setAttribute("allTree", allTree);
		//查询出所有分区
		List<Map<String, Object>> allCameraCategory = cameraService.selectAllCameraCategory();
		request.setAttribute("allCameraCategory", allCameraCategory);
		return "jsp/camera/camera-add";
	}
	
	/**
	 * 新增摄像头
	 * */
	@ResponseBody
	@RequestMapping("/addCamera.do")
	public int addCamera(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		
		map.put("c_status", 1);
		map.put("c_ctime", XVDateUtils.getCurrenTimeMillis());
		System.out.println("摄像头插入  :  "+map);
		
		int re_status = cameraService.addCamera(map);
		System.out.println("结果 : "+re_status);
		return re_status;
	}
	
	/**
	 * 查询所有摄像头
	 * */
	@RequestMapping("/selectAllCamera.do")
	public String selectAllCamera(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		System.out.println("查询  :  "+map);

		List<Map<String, Object>> allCamera = null;
		
		allCamera = cameraService.selectAllCamera();

		int itemCount = allCamera.size();
		
		for (Map<String, Object> map2 : allCamera) {
			if(map2.get("c_ctime") != null) {
				int p = Integer.valueOf(map2.get("c_ctime").toString());
				if(p != 0) {
					map2.put("c_ctime", XVDateUtils.MillisFormat(p));	
				}
			}
			
		}
		
		
		request.setAttribute("allCamera",allCamera);
		return "jsp/camera/camera-list";
	}
	
	/**
	 *修改前查询摄像头详情
	 * */
	@RequestMapping("/preSelectCameraDetails.do")
	public String preSelectCameraDetails(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		Map<String, Object> cameraDetails = cameraService.selectCameraDetails(map);
		
		request.setAttribute("cameraDetails",cameraDetails);
		List<Map<String, Object>> allTree = treeService.selectAllTree();
		request.setAttribute("allTree", allTree);
		//查询出所有分区
		List<Map<String, Object>> allCameraCategory = cameraService.selectAllCameraCategory();
		request.setAttribute("allCameraCategory", allCameraCategory);
		return "jsp/camera/camera-edit";
	}
	
	/**
	 * 修改摄像头
	 * */
	@ResponseBody
	@RequestMapping("/updateCamera.do")
	public int updateCamera(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		System.out.println("摄像头 : "+map);
		int shop = cameraService.updateCameraDetails(map);
		return shop;
	}

	/**
	 * 新增摄像头分类
	 * */
	@ResponseBody
	@RequestMapping("/addCameraCategory.do")
	public int addCameraCategory(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		System.out.println("摄像头 : "+map);
		map.put("cs_status", 0);
		int shop = cameraService.addCameraCategory(map);
		return shop;
	}
	/**
	 * 查询所有摄像头分类
	 * */
	@RequestMapping("/selectAllCameraCategory.do")
	public String selectAllCameraCategory(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		System.out.println("查询  :  "+map);

		List<Map<String, Object>> allCameraCategory = null;
		
		allCameraCategory = cameraService.selectAllCameraCategory();

		int itemCount = allCameraCategory.size();
		
		
		request.setAttribute("allCameraCategory",allCameraCategory);
		return "jsp/camera/camera-category-list";
	}
	/**
	 * 修改前查询摄像头详情
	 * */
	@RequestMapping("/preSelectCameraCategoryDetails.do")
	public String preSelectCameraCategoryDetails(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		Map<String, Object> categoryDetails = cameraService.selectCameraCategoryDetails(map);
		request.setAttribute("categoryDetails", categoryDetails);
		return "jsp/camera/camera-category-edit";
	}
	/**
	 * 修改摄像头分类
	 * */
	@ResponseBody
	@RequestMapping("/updateCameraCategoryDetails.do")
	public int updateCameraCategoryDetails(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		System.out.println("摄像头 : "+map);
		int shop = cameraService.updateCameraCategoryDetails(map);
		return shop;
	}
}